27. CODE: Formatting the Printed Board
Formatting the Printed Board
0 ⛰️ 0 0 0 0
0 ⛰️ 0 0 0 0
0 ⛰️ 0 0 0 0
0 ⛰️ 0 0 0 0
0 0 0 0 ⛰️ 0
The board will eventually have more than two cell states as the program becomes more complicated, and it would be nice to add formatting to the printed output of the board to ensure readability as the number of board states increases.
To accommodate more board states and facilitate print formatting, we have provided the
State
enum with enumerator values
kEmpty
and
kObstacle
. In this exercise, you will write a
CellString
function which converts each
State
to an appropriate string. In the next exercise, we will update the program to use the
enum
values and
CellString
function.
To Complete This Exercise:
- Write a function
CellString
which accepts aState
as input and returns the following string:
"⛰️ "
if the input equals akObstacle
"0 "
otherwise.
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: generic
- Opened files (when workspace is loaded): n/a
-
userCode:
export CXX=g++-7
export CXXFLAGS=-std=c++17
g++() {
/usr/bin/g++-7 -std=c++17 "$1"
}
export -f g++